home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / TUTOROOT.PAK / CNTRLLER.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  183 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1994 by Borland International
  3. //   Tutorial application -- cntrller.cpp
  4. //----------------------------------------------------------------------------
  5. #include <ocf/automacr.h>
  6. #include <iostream.h>
  7. #include <stdlib.h>
  8. #include <conio.h>
  9. #include <math.h>
  10.  
  11. // forward declarations
  12. //
  13. class TDrawAppProxy;
  14.  
  15. class TDrawDocProxy : public TAutoProxy {
  16.   public:
  17.     TDrawDocProxy() : TAutoProxy(DEFAULT_SYSTEM_LANGID) {}
  18.     void SetPenColor(long color);
  19.     long GetPenColor();
  20.     void SetPenSize(int penSize);
  21.     int  GetPenSize();
  22.     void AddPoint(short x, short y);
  23.     void AddLine();
  24.     void ClearLine();
  25.     void Application(TDrawAppProxy& a);
  26. };
  27.  
  28. class TDrawAppProxy : public TAutoProxy {
  29.     public:
  30.     TDrawAppProxy() : TAutoProxy(DEFAULT_SYSTEM_LANGID) {}
  31.     void Show(bool visible);
  32.     void NewDocument();
  33.     void Document(TDrawDocProxy& d);
  34. };
  35.  
  36. long 
  37. TDrawDocProxy::GetPenColor()
  38. {
  39.   AUTOCALL_PROPGET("PenColor");
  40. }
  41.  
  42. void 
  43. TDrawDocProxy::SetPenColor(long color) 
  44. {
  45.   AUTOCALL_PROPSET("PenColor", color);
  46. }
  47.  
  48. void 
  49. TDrawDocProxy::SetPenSize(int penSize) 
  50. {
  51.   AUTOCALL_PROPSET("PenSize", penSize);
  52. }
  53.  
  54. int  
  55. TDrawDocProxy::GetPenSize()            
  56. {
  57.   AUTOCALL_PROPGET("PenSize");
  58. }
  59.  
  60. void 
  61. TDrawDocProxy::AddPoint(short x, short y)
  62. {
  63.   AUTOCALL_METHOD2V("AddPoint", x, y);
  64. }
  65.  
  66. void 
  67. TDrawDocProxy::AddLine()
  68. {
  69.   AUTOCALL_METHOD0V("AddLine");
  70. }
  71.  
  72. void 
  73. TDrawDocProxy::ClearLine()
  74. {
  75.   AUTOCALL_METHOD0V("ClearLine");
  76. }
  77.  
  78. void 
  79. TDrawDocProxy::Application(TDrawAppProxy& a) 
  80. {
  81.   AUTOCALL_PROPREF("Application", a);
  82. }
  83.  
  84. void 
  85. TDrawAppProxy::Show(bool visible)      
  86. {
  87.   AUTOCALL_METHOD1V("Show", visible);
  88. }      
  89.  
  90. void 
  91. TDrawAppProxy::NewDocument()           
  92. {
  93.   AUTOCALL_METHOD0V("NewDocument");
  94. }
  95.  
  96. void 
  97. TDrawAppProxy::Document(TDrawDocProxy& d)    
  98. {
  99.   AUTOCALL_PROPREF("Document", d);
  100. }
  101.  
  102. long Colors[] = {
  103.   RGB(0x00, 0x00, 0x00),
  104.   RGB(0xFF, 0x00, 0x00),
  105.   RGB(0x00, 0xFF, 0x00),
  106.   RGB(0x00, 0x00, 0xFF),
  107.   RGB(0xFF, 0xFF, 0x00),
  108.   RGB(0x00, 0xFF, 0xFF),
  109.   RGB(0xFF, 0x00, 0xFF)
  110. };
  111.  
  112. const int NumColors = sizeof(Colors)/sizeof(Colors[0]);
  113.  
  114. int
  115. OwlMain(int argc, char *argv[])
  116. {
  117.   TOleAllocator allocator;      // OLE requirement
  118.   TDrawAppProxy app;
  119.  
  120.   _InitEasyWin();
  121.  
  122.   try {
  123.     app.Bind("AutoDrawingPad.Application.1");
  124.  
  125.     cout << "Starting the drawing." << endl;
  126.  
  127.     // if there's one argument on the command line,
  128.     // don't display the frame window.
  129.     if (argc == 2) {
  130.       app.Show(false);
  131.     }
  132.     else {
  133.       app.Show(true);
  134.       app.NewDocument();
  135.     }
  136.  
  137.     TDrawDocProxy doc;
  138.     app.Document(doc);
  139.  
  140.     cout << "Current automated pen size: " << doc.GetPenSize() << endl;
  141.     cout << "Current automated pen color: " << doc.GetPenColor() << endl;
  142.  
  143.     double startX   = 150;
  144.     double startY   = 150;
  145.     double radius   = 0;
  146.     double theta    = 0;
  147.     int colorIndex  = 0;
  148.     int penSize     = 1;
  149.     double x        = 0;
  150.     double y        = 0;
  151.  
  152.     doc.AddPoint(startX, startY);
  153.     for (int i=0; radius < 70; i++) {
  154.       if (i % 10 == 0) {
  155.         // use the next pen
  156.         doc.AddLine();
  157.         doc.AddPoint(startX+x, startY-y);
  158.         doc.SetPenColor(Colors[colorIndex++]);
  159.         doc.SetPenSize(penSize++);
  160.         colorIndex %= NumColors;
  161.       }
  162.       radius += 0.2 * theta;
  163.       x = 2 * radius * cos(theta);
  164.       y = 2 * radius * sin(theta);
  165.       doc.AddPoint(startX+x, startY-y);
  166.       theta += 0.2;
  167.     }
  168.     doc.AddLine();
  169.  
  170.     cout << "Hit a key to quit the program." << endl;
  171.     while (!kbhit()) {
  172.     }
  173.  
  174.     cout << endl << "Quiting..." << endl;
  175.     PostQuitMessage(0);
  176.   }
  177.   catch (TXBase& x) {
  178.     cout << x.why() << endl;
  179.   }
  180.   return 0;
  181. }
  182.  
  183.